﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Input;
using Ay.MvcFramework;
using MPSystem.Models;
using Ay.Framework.WPF.Controls;
using Ay.Framework.WPF;
using System.IO;
using Base.DAL;

namespace MPSystem.Controllers
{
    public class HomeController : Controller
    {

        Common common = new Common();

        private ObservableCollection<AyTreeViewItemModel> _LeftSubMenus = new ObservableCollection<AyTreeViewItemModel>();


        /// <summary>
        /// 主页 菜单
        /// </summary>
        public ObservableCollection<AyTreeViewItemModel> LeftSubMenus
        {
            get { return _LeftSubMenus; }
            set { Set(ref _LeftSubMenus, value); }
        }

        /// <summary>
        /// 宽度
        /// </summary>
        private int _GWidth=180;
        public int GWidth
        {
            get { return _GWidth; }
            set { Set(ref _GWidth, value); }
        }
        /// <summary>
        /// 文字
        /// </summary>
        private string _title;
        public string Title
        {
            get { return _title; }
            set { Set(ref _title, value); }
        }
        /// <summary>
        /// 文字
        /// </summary>
        private string _IsHidden;
        public string IsHidden
        {
            get { return _IsHidden; }
            set { Set(ref _IsHidden, value); }
        }

        /// <summary>
        /// 图标
        /// </summary>
        private string _icon;
        public string icon
        {
            get { return _icon; }
            set { Set(ref _icon, value); }
        }
        


        public HomeModel Model { get; set; }
        public HomeController() : base()
        {

            ViewBag.Title = common.GetSystemName();
            ViewBag.GWidth = 180;
            
            // LeftSubMenus = CreateMenuTreeData();

            //MPSystem 1.0 功能列表
            //AyTreeViewItemModel root00 = new AyTreeViewItemModel("首页", "path_home", null, false, "/Views/HomePageView.xaml");
            //AyTreeViewItemModel root1 = new AyTreeViewItemModel("首页", "path_home", null, false);
            //AyTreeViewItemModel root1_0 = new AyTreeViewItemModel("10W数据折线", "path_home", root1, false, "/Views/ZCYL/BigDataLineChart.xaml");


            AyTreeViewItemModel root2 = new AyTreeViewItemModel("综采压力", "fa-dedent", null, false);
            AyTreeViewItemModel root2_9 = new AyTreeViewItemModel("综采在线监测", "fa-battery_full", root2, false, "/Views/ZCYL/ZCYLPage.xaml");

            AyTreeViewItemModel root2_1 = new AyTreeViewItemModel("综采数据处理", "fa-dedent", root2, false);
            AyTreeViewItemModel root2_12 = new AyTreeViewItemModel("综采数据查询", "fa-dedent", root2_1, false, "/Views/DataQuery/DataQuery_CC.xaml");
            AyTreeViewItemModel root2_21 = new AyTreeViewItemModel("综采数据分析", "fa-dedent", root2_1, false, "/Views/DataQuery/DataQuery_ZCAnalysis.xaml");

            AyTreeViewItemModel root2_2 = new AyTreeViewItemModel("综采曲线分析", "fa-lock", root2, false);
            AyTreeViewItemModel root2_22 = new AyTreeViewItemModel("工作阻力对比", "fa-lock", root2_2, false, "/Views/ZCYL/ZCYLPage_EveryDayZLDB.xaml");
            AyTreeViewItemModel root2_23 = new AyTreeViewItemModel("每日工作阻力分析", "fa-lock", root2_2, false, "/Views/ZCYL/ZCYLPage_EveryDayGzzl.xaml");
            AyTreeViewItemModel root2_24 = new AyTreeViewItemModel("支架载荷频度", "fa-lock", root2_2, false, "/Views/ZCYL/ZCYLPage_Freq.xaml");
            AyTreeViewItemModel root2_25 = new AyTreeViewItemModel("历史工作阻力", "fa-lock", root2_2, false, "/Views/ZCYL/ZCYLPage_History.xaml");
            //AyTreeViewItemModel root2_26 = new AyTreeViewItemModel("循环阻力", "fa-lock", root2_2, false, "/Views/ZCYL/ZCYLPage_loop.xaml");
            AyTreeViewItemModel root2_3 = new AyTreeViewItemModel("综采报表", "fa-dedent", root2, false, "/Views/ZCYL/ZCYLPage_test.xaml");
            //AyTreeViewItemModel root2_4 = new AyTreeViewItemModel("活体缩量报表(未做)", "fa-dedent", root2, false, "/Views/ZCYL/ZCYLPage_test.xaml");

            AyTreeViewItemModel root3 = new AyTreeViewItemModel("围岩移动", "fa_puzzle_piece", null, false);
            AyTreeViewItemModel root3_1 = new AyTreeViewItemModel("顶板离层监测", "fa_puzzle_piece", root3, false, "/Views/ZCYL/ZCYLPage_DBLC_Online.xaml");
            //AyTreeViewItemModel root3_3 = new AyTreeViewItemModel("数据列表显示", "fa_puzzle_piece", root3, false, "/Views/WY/DataDispaly_WY.xaml");
            //AyTreeViewItemModel root3_2 = new AyTreeViewItemModel("顶板下沉监测", "fa_puzzle_piece", root3, false, "/Views/ZCYL/ZCYLPage_DBXC_Online.xaml");

            AyTreeViewItemModel root3_4 = new AyTreeViewItemModel("围岩移动数据查询", "fa_puzzle_piece", root3, false, "/Views/DataQuery/DataQuery_WY.xaml");
            AyTreeViewItemModel root3_5 = new AyTreeViewItemModel("围岩移动历史曲线", "fa_puzzle_piece", root3, false, "/Views/ZCYL/ZCYLPage_WY_History.xaml");
            AyTreeViewItemModel root3_6 = new AyTreeViewItemModel("围岩移动监测报表", "fa_puzzle_piece", root3, false, "/Views/ZCYL/ZCYLPage_WY_test.xaml");
            

            

            AyTreeViewItemModel root4 = new AyTreeViewItemModel("锚杆/索应力", "fa_ra", null, false);
            AyTreeViewItemModel root4_2 = new AyTreeViewItemModel("锚杆/索在线监测", "fa_ra", root4, false, "/Views/ZCYL/ZCYLPage_MG_Online.xaml");
            AyTreeViewItemModel root4_3 = new AyTreeViewItemModel("锚杆/索数据查询", "fa_puzzle_piece", root4, false, "/Views/DataQuery/DataQuery_mg.xaml");
            AyTreeViewItemModel root4_4 = new AyTreeViewItemModel("锚杆/索曲线分析", "fa_puzzle_piece", root4, false, "/Views/ZCYL/ZCYLPage_MG_History.xaml");
            AyTreeViewItemModel root4_5 = new AyTreeViewItemModel("锚杆/索监测报表", "fa_puzzle_piece", root4, false, "/Views/ZCYL/ZCYLPage_MG_test.xaml");


            AyTreeViewItemModel root5 = new AyTreeViewItemModel("围岩应力", "fa_ra", null, false);
            AyTreeViewItemModel root5_2 = new AyTreeViewItemModel("围岩应力在线监测", "fa_ra", root5, false, "/Views/ZCYL/ZCYLPage_WYYL_Online.xaml");
            AyTreeViewItemModel root5_3 = new AyTreeViewItemModel("围岩应力数据查询", "fa_puzzle_piece", root5, false, "/Views/DataQuery/DataQuery_wyyl.xaml");
            AyTreeViewItemModel root5_4 = new AyTreeViewItemModel("围岩应力曲线分析", "fa_puzzle_piece", root5, false, "/Views/ZCYL/ZCYLPage_WYYL_History.xaml");
            AyTreeViewItemModel root5_5 = new AyTreeViewItemModel("围岩应力监测报表", "fa_puzzle_piece", root5, false, "/Views/ZCYL/ZCYLPage_WYYL_test.xaml");                        
            AyTreeViewItemModel root7 = new AyTreeViewItemModel("基础编辑", "fa-info-circle", null, false);
            //AyTreeViewItemModel root3_1 = new AyTreeViewItemModel("行详情", "", root3, false, "/Views/AyDataViewDemo15/AyDataViewDemo15View.xaml");

            AyTreeViewItemModel root7_2 = new AyTreeViewItemModel("矿井信息设置", "fa-info-circle", root7, false, "/Views/BasicDataSet/BasicDataSet_SS.xaml");
            //root3_2.IsSelected = true;
            AyTreeViewItemModel root7_3 = new AyTreeViewItemModel("系统参数设置", "fa-info-circle", root7, false, "/Views/BasicDataSet/BasicDataSet_System.xaml");
            ////root3_3.IsSelected = true;
            AyTreeViewItemModel root8 = new AyTreeViewItemModel("其他", "fa_pied_piper_pp", null, false);
            AyTreeViewItemModel root8_1 = new AyTreeViewItemModel("数据接口", "fa_pied_piper_pp", root8, false, "/Views/Others/FTPPage.xaml");
            //AyTreeViewItemModel root8_1_1 = new AyTreeViewItemModel("行详情", "", root8_1, false, "/Views/Others/FTPPage.xaml");
    

            AyTreeViewItemModel root9 = new AyTreeViewItemModel("关于版本", "fa_exclamation", null, false, "/Views/VersionPage.xaml");
            //LeftSubMenus.Add(root1);
            LeftSubMenus.Add(root2);
            LeftSubMenus.Add(root3);
            LeftSubMenus.Add(root4);
            LeftSubMenus.Add(root5);
            var curUser = MPLoginController.CurUser;
            if (curUser.Flag == 0)
            {
                LeftSubMenus.Add(root7);
                LeftSubMenus.Add(root8);
            }
            LeftSubMenus.Add(root9);

            TreeViewItemSelected = inParam =>
             {
                 //dynamic _can = inParam as object[];
                 //dynamic _0 = _can[0].DataContext;
                 AyTreeViewItemModel ami = inParam as AyTreeViewItemModel;
                 if (ami.IsNull()) return;
                 if (ami.ExtValue.IsNotNull())
                 {
                     if ( ConditonsModel.HomeHeight > 100)
                     {
                         ViewBag.SubPageSource2 = new Uri(ami.ExtValue.ToString(), UriKind.RelativeOrAbsolute);
                     }
                     else
                     {
                         ViewBag.SubPageSource = new Uri(ami.ExtValue.ToString(), UriKind.RelativeOrAbsolute);
                     }
                 }
                    
             };

            RCollopse = inParam =>
            {
                if (inParam.ToString() == "0")
                {
                    ViewBag.GWidth = 180; 
                    ViewBag.IsHidden = "Visible";
                }
                else
                {
                    ViewBag.GWidth = 0;
                    ViewBag.IsHidden = "Collapsed";
                }
               
              //  AyMessageBox.ShowInformation(inParam.ToString());
            };
         
        }

        /// <summary>
        /// treeviewItem 选中事件
        /// </summary>
        public ActionResult TreeViewItemSelected { get; private set; }

        /// <summary>
        ///  折叠选中事件
        /// </summary>
        public ActionResult RCollopse { get; private set; }
        public ObservableCollection<AyTreeViewItemModel> CreateMenuTreeData()
        {
            try
            {
                return AyTreeView.CreateMenuFromXml(System.Windows.Forms.Application.StartupPath + "/Contents/Config/sysmenu.xml");
            }
            catch
            {
                return null;
            }
        }


    }
}
